<?
require_once  '../classes/ConnectionDB.php';
require_once  '../classes/ClasseDataManager.php';
require_once  '../classes/TestDataManager.php';
require_once  '../bean/Domanda.php';

$connection =ConnectionDB::getInstance()->connectToDB();
$codiceTest = $_POST["codiceTest"];
$classe = $_POST["classe"];

$studenti = ClasseDataManager::getInstance()->getStudenti($connection, "", "", $classe);

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Nuova sottomissione Test - step 2 - </title>
        <script src="../glassboxLatest/glassbox.2.0.0/javascripts/prototype.js" type="text/javascript"></script>
        <script src="../glassboxLatest/glassbox.2.0.0/javascripts/scriptaculous/effects.js" type="text/javascript"></script>
        <script src="../glassboxLatest/glassbox.2.0.0/javascripts/glassbox/glassbox.js" type="text/javascript"></script>
        <style type="text/css">
            @import url("../css/style.css");

            #testForm {
                padding-top: 3%;
                margin-left: -5px;
            }

            #testFormCont
            {
                padding-left: 2%;
                padding-top: 2%;
            }

            #testFormCont table
            {

            }
        </style>
        <script type="text/javascript">
            path_to_root_dir = "../glassboxLatest/glassbox.2.0.0/";
            var listaDomande;
            var numItem=10;
            var currentIndex=0;

            window.onload = function()
            {
                var testForm = new GlassBox();
                testForm.init( 'testForm', '1040px', '590px', 'auto','',true, false);
                testForm.ipos();
                testForm.appear();
            }



            function handler() {
                if(this.readyState == 4 && this.status == 200)
                {

                    document.formReload.submit();

                } else if (this.readyState == 4 && this.status != 200) {
                    // fetched the wrong page or network error...
                    alert("error this.status : " + this.status );

                }
            }

            function xXMLHttpRequest()
            {

                var client = null;
                if (window.XMLHttpRequest)
                {
                    client=new XMLHttpRequest();
                }
                // code for IE
                else if (window.ActiveXObject)
                {
                    client=new ActiveXObject("Microsoft.XMLHTTP");
                }

                return client;
            }

            function riattivaTestPerStudente(codiceStudenteToUpdate)
            {
                var client = xXMLHttpRequest();
                client.onreadystatechange = handler;

                var param = "operation=updateStatoStudenteTest"+
                    "&codiceTest=<?= $_POST["codiceTest"] ?>"+
                    "&codiceStudente="+codiceStudenteToUpdate;
                client.open("POST", "newTestListener.php", true);
                client.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

                client.send(param);

            }


        </script>
    </head>



    <body>
        <?php include '../portal/header.php';?>
        <center>



            <form name="formReload" method="POST" action="liveTestRes.php">
                <input type="hidden" name="codiceTest" value="<?= $_POST["codiceTest"] ?>" />
                <input type="hidden" name="nomeTest" value="<?= $_POST["nomeTest"] ?>" />
                <input type="hidden" name="ore" value="<?= $_POST["ore"] ?>" />
                <input type="hidden" name="minuti" value="<?= $_POST["minuti"] ?>" />
                <input type="hidden" name="key" value="<?= $_POST["key"] ?>" />
                <input type="hidden" name="classe" value="<?= $_POST["classe"] ?>" />
            </form>

            <form method="POST" action="newTestListener.php" id="formSottTest">

                <div id="testForm">
                    <div id="testFormCont">
                        <input type="hidden" name="codiceTest" value="<?= $_POST["codiceTest"] ?>" />
                        <input type="hidden" name="nomeTest" value="<?= $_POST["nomeTest"] ?>" />
                        <input type="hidden" name="ore" value="<?= $_POST["ore"] ?>" />
                        <input type="hidden" name="minuti" value="<?= $_POST["minuti"] ?>" />
                        <input type="hidden" name="key" value="<?= $_POST["key"] ?>" />
                        <input type="hidden" name="classe" value="<?= $_POST["classe"] ?>" />
                        <input type="hidden" name="operation" value="sottomettiTest" />
                        <table >
                            <tr>
                                <td>Codice test : </td>
                                <td><?= $_POST["codiceTest"] ?></td>
                            </tr>
                            <tr>
                                <td>Nome test : </td>
                                <td><?= $_POST["nomeTest"] ?></td>
                            </tr>
                            <tr>
                                <td>Ore test : </td>
                                <td><?= $_POST["ore"] ?></td>
                            </tr>
                            <tr>
                                <td>Minuti test : </td>
                                <td><?= $_POST["minuti"] ?></td>
                            </tr>
                            <tr>
                                <td>Key generata</td>
                                <td><?= $_POST["key"] ?></td>
                            </tr>

                        </table>
<br /><br />
                        <div id="results">
                            <div id="resultsCont">
                                <table id='tableResults' width="100%" border="1">
                                    <tr>
                                        <th>Codice Studente</th>
                                        <th>Nome</th>
                                        <th>Cognome</th>
                                       <!-- <th>Stato test</th>
                                        <th>Riattiva</th>-->
                                    </tr>
                                    <? for($i=0; $i<count($studenti); $i++)
                                    {?>
                                    <tr>
                                        <td style="text-align: center"><?= $studenti[$i]->getCodiceStudente(); ?></td>
                                        <td><?= $studenti[$i]->getNome(); ?></td>
                                        <td><?= $studenti[$i]->getCognome(); ?></td>

                                    </tr>
                                        
                                    <?}?>
                                </table>
                            </div>
                        </div>
                        <br /><br /><br />
                        <input type="submit" value="Completa" />
                    </div>
                </div>
            </form>

        </center>
    </body>
</html>
